var api = require('utils/request.js').default;

// app.js
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    wx.cloud.init({
      env:'dev-3g27hm367c3fbe54'
    })
    // 登录
    wx.login({
      success: res => {
        console.log(res.code,'code')
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        var data = {
          code: res.code
        }
        wx.request({
          url: 'https://wms-prod.progengroup.com/common/common/volumeAppLogin?code=' + res.code,
          method: 'POST',
          success(res){
            console.log(res)
            if(res.data.code == 200){
              wx.setStorageSync('userid', res.data.data)

              wx.request({
                url: 'https://wms-prod.progengroup.com/common/volumeUser/' + res.data.data,
                method: 'GET',
                success(res){
                  console.log(res)
                  wx.setStorageSync('volumeJson', res.data.data.volumeJson)
                }
              })
            }
          }
        })

        // api.volumeAppLogin(data).then(res =>{
        //   console.log(res)
        //   if(res.data.code == 200){
        //     wx.setStorageSync('userid', res.data.msg)
        //     wx.request({
        //       url: 'http://192.168.3.42:9999/common/volumeUser?userId=' + res.data.msg,
        //       header: {
        //         'content-type': 'application/json' // 默认值
        //       },
        //       method: 'POST',
        //       success(res){
        //         console.log(res)
        //       }
        //     })
        //   }
        // })
      }
    })
  },
  globalData: {
    userInfo: null
  }
})
